from django.shortcuts import render
from django.core import paginator
from django.db.models.query import QuerySet
from django.shortcuts import get_object_or_404, render
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from .models import Story


def index(request):
    storys = Story.objects.order_by('-story_published_date')

    paginator = Paginator(storys, 3)
    page = request.GET.get('page')
    paged_storys = paginator.get_page(page)
    context = {
        'storys':paged_storys
    }

    return render(request, 'storys/storys.html', context)

def story(request, story_id):
    story = get_object_or_404(Story, pk=story_id)

    context = {
        'story' : story
    }

    return render(request, 'storys/story.html', context)